package com.foreknow.demo8;

import java.util.*;

public class MapExam {
    public static void main(String[] args) {
        //创建List集合
        List<Map<String,Person>> list = new ArrayList<>();
        //创建三个Map容器，每个Map保存2个对象
        Map<String,Person> map1 = new HashMap<>();
        Person p1 = new Person(1,"tom",20);
        Person p2= new Person(2,"fender",21);
        map1.put("p1",p1);
        map1.put("p2",p2);
        Map<String,Person> map2 = new HashMap<>();
        Person p3 = new Person(3,"tom3",23);
        Person p4= new Person(4,"fender4",24);
        map2.put("p3",p3);
        map2.put("p4",p4);
        Map<String,Person> map3 = new HashMap<>();
        Person p5 = new Person(5,"tom5",25);
        Person p6= new Person(6,"fender6",26);
        map3.put("p5",p5);
        map3.put("p6",p6);
        //将Map添加到List集合中
        list.add(map1);
        list.add(map2);
        list.add(map3);
        //输出所有Person对象信息(遍历List 然后遍历map集合)
        for(int i = 0;i<list.size();i++){
            Map<String,Person> maps = list.get(i);
            Set<Map.Entry<String,Person>> s = maps.entrySet();
            Iterator<Map.Entry<String,Person>> it = s.iterator();
            while (it.hasNext()){
                Map.Entry<String,Person> entry = it.next();
                String k = entry.getKey();
                Person v = entry.getValue();
                System.out.println(k+"-----"+v.getName());
            }
        }
    }
}
